/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.repository;

import me.zhengjie.modules.system.domain.ExamResult;
import me.zhengjie.modules.system.domain.WxUser;
import me.zhengjie.modules.system.domain.vo.LastMonthNewUserVo;
import me.zhengjie.modules.system.service.dto.WxUserDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
* @website https://el-admin.vip
* @author zhaoxiancheng
* @date 2021-11-23
**/
public interface WxUserRepository extends JpaRepository<WxUser, Integer>, JpaSpecificationExecutor<WxUser> {

    @Query("select new me.zhengjie.modules.system.domain.vo.LastMonthNewUserVo(substring(t.subscribeTime,1,10) ,count(t.id)) from WxUser t where t.subscribeTime >= :subscribeTimeFrom and t.subscribeTime <= :subscribeTimeTo group by substring(t.subscribeTime,1,10)")
    List<LastMonthNewUserVo> countLastMonthUser(@Param("subscribeTimeFrom") String subscribeTimeFrom, @Param("subscribeTimeTo") String subscribeTimeTo);

    @Query(value = "select * from wx_user where  mobile = :moblie ", nativeQuery = true)
    List<WxUser> findByMoblie(@Param("moblie") String moblie);

    @Query(value = "select * from wx_user where  city = :city ", nativeQuery = true)
    List<WxUser> findByCity(@Param("city") String city);

    @Query(value = "select * from wx_user where  city = :city and mobile = :mobile ", nativeQuery = true)
    List<WxUser> findByParam(@Param("city") String city,@Param("mobile") String mobile);
}